package org.example.dfs;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyishan
 * @date 2023/9/1 10:25
 * @apiNote
 */

public class Test00078Subsets {

    public static void main(String[] args) {
        int[] nums = {1,2,3};
        List<List<Integer>> res= subsets(nums);
        System.out.println(JSON.toJSON(res));
    }

    public static List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        dfs(nums,list,res,0);
        return res;
    }

    public static void dfs(int[] nums, List<Integer> list,List<List<Integer>> res,int index){
        if(index==nums.length){
            res.add(new ArrayList<>(list));
            return;
        }
        dfs(nums,list,res,index+1);
        list.add(nums[index]);
        dfs(nums,list,res,index+1);
        list.remove(list.size()-1);
    }



}
